package com.ebelter.bpm.activitys;


import android.app.Dialog;

import android.view.View;
import android.widget.TextView;
import com.ebelter.bpm.R;
import com.ebelter.btcomlib.bases.activity.BaseActivity;
import com.ebelter.btcomlib.models.bluetooth.products.bpm.BpmManager;
import com.ebelter.btcomlib.utils.StringUtils;
import com.ebelter.btcomlib.views.dialogs.TextTipDialog;

public class BPM_DeviceManagerActivity extends BaseActivity {

    private static final String TAG="BPM_DeviceManagerActivity";


    TextView topTitleTv;
    TextView address_tv;

    private BpmManager mBpmManager;


    @Override
    protected int loadLayoutById() {
        return R.layout.activity_bpm_devicemaneger;
    }
    @Override
    protected void initView() {
        FV();
    }

    private void FV() {
        topTitleTv=findViewById(R.id.top_title_tv);
        address_tv=findViewById(R.id.devicemanager_mac_address_tv);

    }

    @Override
    protected boolean isOpenBlueStationListener() {
        return false;
    }


//    @Override
//    protected void bluetoothStationReceive(Intent intent, String action) {
//        if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
//            int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
//            switch (state) {
//                case BluetoothAdapter.STATE_OFF:
//                    LogUtils.i(TAG, "STATE_OFF 手机蓝牙关闭");
//
//                    break;
//                case BluetoothAdapter.STATE_TURNING_OFF:
//                    LogUtils.i(TAG, "STATE_TURNING_OFF 手机蓝牙正在关闭");
//
//                    break;
//                case BluetoothAdapter.STATE_ON:
//                    LogUtils.i(TAG, "STATE_ON 手机蓝牙开启");
//
//                    break;
//                case BluetoothAdapter.STATE_TURNING_ON:
//                    LogUtils.i(TAG, "STATE_TURNING_ON 手机蓝牙正在开启");
//                    break;
//            }
//        }
//    }

    @Override
    protected void initData() {
        topTitleTv.setText(R.string.device_management);
        mBpmManager=new BpmManager(this);
        address_tv.setText("名字"+" ("+mBpmManager.getBondDeviceAddress()+")");
    }

    //解绑设备
    public void unpairClick(View view){
        TextTipDialog textTipDialog=new TextTipDialog(this, StringUtils.getResStr(R.string.device_management_remove_tip));
        textTipDialog.setListener(new TextTipDialog.ICancelOkBtListener() {
            @Override
            public void cancel(Dialog dialogView) {
                dialogView.cancel();
            }

            @Override
            public void ok(Dialog dialogView) {
                dialogView.cancel();
                mBpmManager.setBondDeviceAddress(null);
                finish();//直接退出
            }
        });
        textTipDialog.show();

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mBpmManager!=null){
            mBpmManager.exit();
            mBpmManager=null;
        }
    }


    public void backClick(View view){
        finish();
    }
}
